package com.ftx.controller.test.future;

import javax.inject.Inject;
import java.util.concurrent.CompletableFuture;

/**
 * Created by fengtingxin on 2021/2/2 8:40 下午
 */
public class TransferServiceImpl implements TransferService {

    @Inject
    private  AccountService accountService; // 使用依赖注入获取账户服务的实例

    @Override
    public CompletableFuture<Void> transfer(int fromAccount, int toAccount, int amount) {
        return accountService.add(fromAccount,-1 * amount)
                .thenAccept( v -> accountService.add(toAccount,amount));
    }
}
